package com.gnar.dis;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.Display;

//TODO: Repurpose class into an Accelerometer object wrapper - new Class name - CP
//TODO: EventHandler can be a singleton as a phone has only one accelerometer - CP
public class EventHandler implements SensorEventListener {

	private float mSensorX;
	private float mSensorY;
	private long mSensorTimeStamp;
	private long mCpuTimeStamp;
	private Display mDisplay;
	private SensorManager mSensorManager;
		
	public EventHandler(Display display, SensorManager sensorManager){
		mDisplay = display;
		mSensorManager = sensorManager;
		mSensorManager.registerListener(
			this,
	 		mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
			SensorManager.SENSOR_DELAY_UI
		);
	}
	

	public void onSensorChanged(SensorEvent event) {
		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			//TODO: This could probably update a member vector -CP
			mSensorX = event.values[1];
			mSensorY = event.values[0];	
		}
		mSensorTimeStamp = event.timestamp;
		mCpuTimeStamp = System.nanoTime();
	}
	
	//TODO:Get the Vector in a single function call- CP
	public float getSensorX() {
		return mSensorX;
	}
	
	public float getSensorY() {
		return mSensorY;
	}
	public long getSensorTimeStamp() {
		return mSensorTimeStamp;
	}
	
	public long getCpuTimeStamp() {
		return mCpuTimeStamp;
	}
}
